package com.ipacs.abs4j.testcode.absSchema;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class TransactionalDefinitionParser extends AbstractAbsBeanDefinitionParser {
	
	protected Class<TransactionalMessageProcessor> getBeanClass(Element element){
		return TransactionalMessageProcessor.class	;
		
	}
	
	protected void doParse(Element element,ParserContext ctx,BeanDefinitionBuilder builder) {
		
		ManagedList<BeanDefinition> Processors= new ManagedList<BeanDefinition>() ;
		String timeOut = element.getAttribute("timeOut") ;
		String PROPAGTION = element.getAttribute("PROPAGTION") ;
		if(StringUtils.hasText(timeOut)) {  			
			builder.addPropertyValue("timeOut", timeOut) ;						
		}
		if(StringUtils.hasText(timeOut)) {  			
			builder.addPropertyValue("PROPAGTION", PROPAGTION) ;						
		}
		
		NodeList nl = element.getChildNodes() ;				
        for(int i =0 ;i<nl.getLength();++i) {			
			Node node = (Node) nl.item(i) ;
			String nodename = node.getNodeName() ;			
			System.out.println("Transactional parser: " + nodename);
			if(node.getNodeType()==1) {								
				Element elem = (Element) node ;	 
				BeanDefinitionParserDelegate pd = new BeanDefinitionParserDelegate(ctx.getReaderContext()) ;
				BeanDefinition bd= pd.parseCustomElement(elem, builder.getBeanDefinition()) ;
				Processors.add(bd) ; 	
			}			
		}
		this.commonParse(element, builder);
		builder.addPropertyValue("processChain", Processors) ;
		
		
	}

}
